package edu.hebeu.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import edu.hebeu.entity.Department;
import edu.hebeu.entity.Employee;
import edu.hebeu.entity.Overtime;
import edu.hebeu.mapper.DepartmentMapper;
import edu.hebeu.mapper.EmployeeMapper;
import edu.hebeu.mapper.OvertimeMapper;
import edu.hebeu.service.OvertimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Repository
public class OvertimeServiceImpl  extends ServiceImpl<OvertimeMapper, Overtime> implements OvertimeService {
    @Autowired
    private  OvertimeMapper overtimeMapper;
    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Page<Overtime> selectPag(Integer employeeNumber, Integer pageNo) {
        Page<Overtime> page = new Page<>(pageNo, 4, "id");
        page.setAsc(false);
        page.equals(employeeNumber);
        EntityWrapper<Overtime> wrapper = new EntityWrapper<>();
        List<Overtime> list = baseMapper.selectPage(page, wrapper);
        for (Overtime overtime : list) {
            setObject(overtime);
        }
        page.setRecords(list);
        return page;
    }

    private void setObject(Overtime overtime) {
        Integer departmentNumber = overtime.getDepartmentNumber();
        Department department = departmentMapper.selectByNumber(departmentNumber);
        overtime.setDepartment(department);
        Integer employeeNumber = overtime.getEmployeeNumber();
        Employee employee = employeeMapper.selectByNumber(employeeNumber);
        overtime.setEmployee(employee);
    }


}
